<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.Calendar"%> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>账单支付</title>
<LINK href="images/css.css" type="text/css" rel="stylesheet">
<script type="text/javascript">

	var req;
	
	function init() {
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	//根据业主ID查询DropChangeAJAXAction，获得该业主账户余额
	function getBalance() {
		init();
		var url="dropChangeAJAX.do?method=getBalance&ownerId="+escape(document.forms[0].ownerId.value);
		
		req.open("get", url, true);
		req.onreadystatechange = callback;
		req.send(null);
	}
	
	function callback() {
		if (4 == req.readyState) {
			if (200 == req.status) {
				//如果响应成功，读取响应数据
				var info = req.responseText;
				document.getElementById("balanceSpan").innerHTML=info;
			}
		}
	}
	function countChange() {
		var amount = document.forms[0].amount.value;
		var paidAmount = document.forms[0].paidAmount.value;
		var change = paidAmount-amount;

		if (change<0) {
			alert("实收金额必须大于应收金额！");
			return false;
		}
		document.forms[0].change.value = Math.round(change*100)/100; 
	}
	
	function checkForm() {
		var paidAmount = document.forms[0].paidAmount.value;
		if (paidAmount==0) {
			alert("请输入实收金额！");
			return false;
		}
		return true;
	}
</script>
</head>

<body>
<html:form action="bill.do?method=paySave" method="post" onsubmit="return checkForm();">
<html:hidden property="id" value="${bill.id}" />
<html:hidden property="ownerId" value="${bill.house.owner.id }" />
<html:hidden property="isPreCharged" value="${isPreCharged }" />
<html:hidden property="wantMoney" value="${wantMoney }" />
<table align="center" width="60%" border="0">
	<tr>
		<td class="STYLE4" align="center" bgcolor="#ffffff" height="40">账单支付</td>
	</tr>
	<tr><td>
	<table align="center" class="tableline" cellspacing="1" cellpadding="0" width="100%" border="0">
	<tr>
		<td width="217" height="26" bgcolor="#ffffff" colspan="2">
		&nbsp;&nbsp;小区：${bill.house.building.subDistrict.name}&nbsp;&nbsp;房产编号：${bill.house.houseId }&nbsp;&nbsp;业主：${bill.house.owner.name }&nbsp;&nbsp;账单日期：<c:if test="${isHistoryBill eq 0}">(${bill.year }年${bill.month }月)</c:if><c:if test="${isHistoryBill eq 1}">(历史欠费)</c:if></td>
	</tr>
	<tr>
		<td width="217" height="26" align="right" bgcolor="#ffffff">应收：</td>
		<td width="773" bgcolor="#ffffff">
		<c:if test="${isPreCharged eq 0 }">
			&nbsp;<html:text property="amount" value="${bill.amount }" disabled="true"/>
		</c:if>
		<c:if test="${isPreCharged eq 1 }">
			&nbsp;<html:text property="amount" value="${realWantMoney }" disabled="true"/>
		</c:if>		
		</td>
	</tr>
	<tr>
		<td width="217" height="26" align="right" bgcolor="#ffffff">实收：</td>
		<td width="773" bgcolor="#ffffff">
		&nbsp;<html:text property="paidAmount" onblur="countChange();"/>
		&nbsp;&nbsp;<a href="#" onclick="getBalance();">查看账户余额</a>&nbsp;<span id="balanceSpan" style="color:red"></span>
		</td>
	</tr>	
    <tr>
      <td width="217" height="26" align="right" bgcolor="#ffffff">找零：</td>
      <td width="773" bgcolor="#ffffff">
      &nbsp;<html:text property="change"/>
      &nbsp;&nbsp;<html:submit value="现金支付" />
      &nbsp;&nbsp;<a href="bill.do?method=accountPaySave&id=${bill.id }&isPreCharged=${isPreCharged }&wantMoney=${wantMoney }">账户支付</a>
      &nbsp;&nbsp;<a href="#">申请减免收费</a>&nbsp;<span style="color:red">${paidError }${accountNotFound }${accountBalanceInsufficient }${depositSubAccountNotOpen }</span>			
	  </td>
    </tr> 
    </table>
    </td></tr>	
</table>
</html:form>
</body>
</html>